sudo apt install exim4
sudo dpkg-reconfigure exim4-config
General type of mail configuration
mail sent by smarthost; received via SMTP or fetchmail
System mail name
Leave default
This is the name that will appear in the To:
field of the email you receive. E.g. root@home-pc
IP-addresses to listen on for incoming SMTP connections
Leave default
127.0.0.1 ; ::1
Other destinations for which mail is accepted
Leave default (Same as “System mail name”)
home-pc
Machines to relay mail for
Leave empty.
IP address or host name of the outgoing smarthost
smtp.gmail.com::587
Hide local mail name in outgoing mail?
Leave default
No
Keep number of DNS-queries minimal (Dial-on-Demand)?
Leave default
No
Delivery method for local mail
Leave default
mbox format in /var/mail/
Split configuration into small files?
Leave default
No
Root and postmaster mail recipient
Put your OS’ user here
your_user
This will add the alias root: your_user
to /etc/aliases
Note: this config only appears if you don’t yet have an alias for root in /etc/aliases
.
If you set this config, it will not appear again when re-running sudo dpkg-reconfigure exim4-config
Enable 2-step verification to your Google account
https://myaccount.google.com/signinoptions/two-step-verification
Create an app password
Configure exim4 to use your Google credentials
sudo nano /etc/exim4/passwd.client
Add the following line
smtp.gmail.com:{your_email_user}@gmail.com:{app_password}
sudo nano /etc/aliases
Add the following line
{your_os_user}: {your_email}
sudo systemctl restart exim4
echo "This is the body of the email" | mail -s "This is the subject line" root
tail -f /var/log/exim4/mainlog
Other related commands
sudo service exim4 restart
sudo update-exim4.conf
sudo exim4 -qff